package com.travel.controller.auth;

import com.travel.model.dto.auth.*;
import com.travel.model.dto.common.ApiResponse;
import com.travel.service.Service.AuthService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
//用户登录注册接口 , 登录, 注册, 修改密码 , 获取用户信息 
@Tag(name = "用户登录注册", description = "用户登录注册相关接口")
@RestController
@RequestMapping("/api/auth")
@RequiredArgsConstructor
public class AuthController {

    private final AuthService authService;

    @Operation(summary = "用户登录", description = "用户使用用户名和密码登录系统")
    @PostMapping("/login")
    public ApiResponse<JwtResponse> login(@Valid @RequestBody LoginRequest loginRequest) {
        JwtResponse response = authService.login(loginRequest);
        return ApiResponse.success("登录成功", response);
    }

    @Operation(summary = "管理员登录", description = "管理员使用账号密码登录系统")
    @PostMapping("/admin/login")
    public ApiResponse<JwtResponse> adminLogin(@Valid @RequestBody AdminLoginRequest loginRequest) {
        JwtResponse response = authService.adminLogin(loginRequest);
        return ApiResponse.success("管理员登录成功", response);
    }

    @Operation(summary = "用户注册", description = "新用户注册账号")
    @PostMapping("/register")
    public ApiResponse<Void> register(@Valid @RequestBody RegisterRequest registerRequest) {
        authService.register(registerRequest);
        return ApiResponse.success("注册成功");
    }

    @Operation(summary = "修改密码", description = "用户修改密码")
    @PostMapping("/password/change")
    public ApiResponse<Void> changePassword(@Valid @RequestBody PasswordChangeRequest request) {
        authService.changePassword(request);
        return ApiResponse.success("密码修改成功");
    }
} 